package com.hakim.wfb.customer.service.impl;

import com.hakim.wfb.bean.ConsumeRecord;
import com.hakim.wfb.biz.ConsumeRecordBiz;
import com.hakim.wfb.customer.params.trans.GetConsumeRecordParameter;
import com.hakim.wfb.customer.params.trans.GetTeamConsumeRecordParameter;
import com.hakim.wfb.customer.result.trans.ConsumeRecordView;
import com.hakim.wfb.customer.result.trans.PointOrderView;
import com.hakim.wfb.customer.result.trans.TeamConsumeRecordView;
import com.hakim.wfb.customer.service.ConsumeRecordService;
import com.hakim.wfb.customer.service.convert.ConsumeRecordDtv;
import com.hkfs.fundamental.api.data.ListResultEx;
import com.hkfs.fundamental.api.data.ObjectResultEx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/7.
 */
@Service("consumeRecordService")
public class ConsumeRecordServiceImpl implements ConsumeRecordService {
    @Autowired
    private ConsumeRecordBiz consumeRecordBiz;

    @Override
    public ListResultEx<ConsumeRecordView> getFinishedConsumeRecords(GetConsumeRecordParameter param) {

        ListResultEx<ConsumeRecordView> result = new ListResultEx<>();
        if (param.getSessionIdentity() == null || param.getSessionIdentity().getUuid() == null || param.getSessionIdentity().getUuid().equals(""))
            return result.makeFailedResult();

        List<ConsumeRecordView> listView = new ArrayList<>();
        List<ConsumeRecord> list = consumeRecordBiz.getFinishedConsumeRecords(param);

        //json重整
        for (int i = 0; i < list.size(); i++) {
            listView.add(ConsumeRecordDtv.convert(list.get(i)));
        }
        result.setPageSize(param.getPageSize());
        result.setPageNo(param.getPageNo());
        result.setDataList(listView);
        result.setTotalCount(consumeRecordBiz.getFinishedConsumeRecordCount(param));
        return result.makeSuccessResult();
    }

    @Override
    public ListResultEx<ConsumeRecordView> getRunningConsumeRecords(GetConsumeRecordParameter param) {

        ListResultEx<ConsumeRecordView> result = new ListResultEx<>();
        if (param.getSessionIdentity() == null || param.getSessionIdentity().getUuid() == null || param.getSessionIdentity().getUuid().equals(""))
            return result.makeFailedResult();

        List<ConsumeRecordView> listView = new ArrayList<>();
        List<ConsumeRecord> list = consumeRecordBiz.getRunningConsumeRecords(param);

        //json重整
        for (int i = 0; i < list.size(); i++) {
            listView.add(ConsumeRecordDtv.convert(list.get(i)));
        }
        result.setPageSize(param.getPageSize());
        result.setPageNo(param.getPageNo());
        result.setDataList(listView);
        result.setTotalCount(consumeRecordBiz.getRunningConsumeRecordCount(param));
        return result.makeSuccessResult();
    }

    /**
     * 用户投资记录
     *
     * @param param
     * @return
     */
    @Override
    public ListResultEx<ConsumeRecordView> getUserConsumeRecords(GetConsumeRecordParameter param) {

        ListResultEx<ConsumeRecordView> result = new ListResultEx<>();
        if (param.getSessionIdentity() == null || param.getSessionIdentity().getUuid() == null || param.getSessionIdentity().getUuid().equals(""))
            return result.makeFailedResult();
        List<ConsumeRecordView> listView = new ArrayList<>();
        List<ConsumeRecord> list = consumeRecordBiz.getUserConsumeRecords(param);

        //json重整
        for (int i = 0; i < list.size(); i++) {
            listView.add(ConsumeRecordDtv.convert(list.get(i)));
        }
        result.setPageSize(param.getPageSize());
        result.setPageNo(param.getPageNo());
        result.setDataList(listView);
        result.setTotalCount(consumeRecordBiz.getUserConsumeRecordsCount(param));
        return result.makeSuccessResult();
    }

    /**
     * 获取团队投资记录
     *
     * @param param
     * @return
     */
    @Override
    public ListResultEx<TeamConsumeRecordView> getTeamConsumeRecords(GetTeamConsumeRecordParameter param) {

        ListResultEx<TeamConsumeRecordView> result = new ListResultEx<>();
        if (param.getSessionIdentity() == null || param.getSessionIdentity().getUuid() == null ||
                param.getSessionIdentity().getUuid().equals(""))
            return result.makeFailedResult();

        List<TeamConsumeRecordView> listView = consumeRecordBiz.getTeamConsumeRecords(param);
        result.setPageSize(param.getPageSize());
        result.setPageNo(param.getPageNo());
        result.setDataList(listView);
        result.setTotalCount(consumeRecordBiz.getTeamConsumeRecordsCount(param));
        return result.makeSuccessResult();
    }

    /**
     * 用户投资中总额
     *
     * @param userId
     * @return
     */
    @Override
    public ObjectResultEx<BigDecimal> getUserInvestingAmount(String userId) {
        ObjectResultEx objectResultEx = new ObjectResultEx();
        objectResultEx.setDataObject(consumeRecordBiz.getUserInvestingAmount(userId));
        return objectResultEx.makeSuccessResult();
    }

    /**
     * 团队投资中总额
     *
     * @param userOrg
     * @return
     */
    @Override
    public ObjectResultEx<BigDecimal> getTeamInvestingAmount(String userOrg) {
        ObjectResultEx objectResultEx = new ObjectResultEx();
        objectResultEx.setDataObject(consumeRecordBiz.getTeamInvestingAmount(userOrg));
        return objectResultEx.makeSuccessResult();
    }
}
